package com.baizhi.service.impl;

import com.baizhi.dao.CmfzLogDao;
import com.baizhi.entity.CmfzLog;
import com.baizhi.service.CmfzLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CmfzLogServiceImpl implements CmfzLogService {
    @Autowired
    private CmfzLogDao cmfzLogDao;

    @Override
    @Transactional(readOnly = true)
    public Page<CmfzLog> selectPage(Integer page, Integer limit, String type) {
        //准备分页对象  设置分页信息
        Page<CmfzLog> cmfzLogPage = new Page<>(page, limit);
        //准备条件对象
        QueryWrapper<CmfzLog> queryWrapper = new QueryWrapper<>();
        //判断是否传入条件参数  决定最后分页的条件查询对象内容
        if(type!=null){
            queryWrapper.eq("log_type",type);
        }
        Page<CmfzLog> selectPage = cmfzLogDao.selectPage(cmfzLogPage, queryWrapper);
        return selectPage;
    }

    @Override
    public void deleteAnyCmfzLog(List<Integer> ids) {
        //利用mybatis-plus提供的批量删除方法
        cmfzLogDao.deleteBatchIds(ids);
    }
}
